﻿using System.Windows;
using System.Windows.Input;
using DevExpress.Xpf.Grid;
using System.Collections.Generic;
using DevExpress.Xpf.Core;
using ThanNhanTao.Server;

namespace ThanNhanTao
{
    /// <summary>
    /// Interaction logic for TimKiemThuoc.xaml
    /// </summary>
    public partial class frmThanhToanNgoaiTruTimKiem : DXWindow
    {
        #region Fields

        public int rowCount = 0;
        private List<Dm_YeuCau> listYeuCauChon;
        private List<Dm_YeuCau> listDmYeuCauTimKiem;
        public bool laChapNhan;

        #endregion 

        #region Properties

        public List<Dm_YeuCau> ListYeuCauChon
        {
            get
            {
                if (listYeuCauChon == null)
                    listYeuCauChon = new List<Dm_YeuCau>();
                return listYeuCauChon;
            }
            set
            {
                listYeuCauChon = value;
            }
        }

        #endregion

        #region Constructor

        public frmThanhToanNgoaiTruTimKiem()
        {
            InitializeComponent();

            this.gridDmYeuCau.Focus();
        }

        #endregion

        #region Other Proccessing

        public void SearchDmYeuCau(List<Dm_YeuCau> listDmYeuCau,List<ChiDinh> listChiDinh, string maYeuCau, string tenYeuCau, byte focusColumn)
        {
            listDmYeuCauTimKiem = listDmYeuCau;
            //foreach (var item in listChiDinh)
            //{
            //    listDmYeuCauTimKiem.Remove(item.Dm_YeuCau);
            //}
            gridDmYeuCau.DataSource = listDmYeuCauTimKiem;
            rowCount = gridDmYeuCau.VisibleRowCount;
        }

        #endregion

        #region Events

        /// <summary>
        /// tbvDmYeuCau_MouseDoubleClick
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event</param>
        private void tbvDmYeuCau_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            //if (gridDmYeuCau.View.GetRowHandleByMouseEventArgs(e) == GridControl.InvalidRowHandle)
            //    return;

            //if (this.gridDmYeuCau.GetFocusedRow() == null)
            //    return;

            //DmDCBietDuocDto = (DmDCBietDuocDto)this.gridDmYeuCau.GetFocusedRow();
            //this.Close();
        }

        /// <summary>
        /// tbvDmYeuCau_PreviewKeyDown
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event</param>
        private void tbvDmYeuCau_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            //if (e.Key == Key.Enter)
            //{
            //    if (gridDmYeuCau.GetFocusedRow() == null)
            //        return;

            //    DmDCBietDuocDto = (DmDCBietDuocDto)this.gridDmYeuCau.GetFocusedRow();
            //    this.Close();
            //}
        }

        #endregion

        private void gridDmYeuCau_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                ListYeuCauChon.Clear();
                this.Close();
            }
        }

        private void btnDong_Click(object sender, RoutedEventArgs e)
        {
            ListYeuCauChon.Clear();
            this.Close();
        }

        private void btnHoanThanh_Click(object sender, RoutedEventArgs e)
        {
            laChapNhan = true;
            ListYeuCauChon = listDmYeuCauTimKiem.FindAll(u => u.CheckItem);
            this.Close();
        }
    }
}
